//
//  WSVerticalGradientColorView.m
//  CharonTVProject
//
//  Created by karong on 2023/8/3.
//

#import "WSVerticalGradientColorView.h"
@interface WSVerticalGradientColorView ()

@property (nonatomic, assign) CGRect gradientLayerFrame;
@property (nonatomic, strong) CAGradientLayer *gradientLayer;

@end

@implementation WSVerticalGradientColorView

- (void)setupGradientLayer {
    
    CAGradientLayer *layer = [[CAGradientLayer alloc] init];
    CGRect frame = self.bounds;
    if (CGRectEqualToRect(self.gradientLayerFrame, CGRectZero)) {
        layer.frame = frame;
    } else {
        layer.frame = self.gradientLayerFrame;
    }

    if (self.color1 && self.color2) {
        layer.colors = @[(__bridge id)self.color1.CGColor,
                         (__bridge id)self.color2.CGColor];
    } else {
        layer.colors = @[(__bridge id)[UIColor colorFromHexRGB:@"F9661A"].CGColor,
                         (__bridge id)[UIColor colorFromHexRGB:@"DD2D08"].CGColor];
    }


    layer.startPoint = CGPointMake(0, 0);
    layer.endPoint = CGPointMake(0, 1);
    [self.layer insertSublayer:layer atIndex:0];
    self.gradientLayer = layer;
}

@end
